/**
 * created at 01.11.2010, 09:28:51
 */
package de.jmda.web.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * @author rowe.jmda@gmail.com
 */
public class JMDAWebEntryPoint implements EntryPoint
{
	private final static int totalWidthPx   = 1024;
	private final static int totalHeigthPx  =  768;
	private final static int centerWidthPx  =  735;
	private final static int centerHeigthPx =  700;

	private class TreeSelectionHandler implements SelectionHandler<TreeItem>
	{
    @Override
    public void onSelection(SelectionEvent<TreeItem> event)
    {
    	TreeItem selectedTreeItem = event.getSelectedItem();
    	
    	HTML html;
    	
    	if (selectedTreeItem == trtmHome)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.home().getText());
    	}
    	else if (selectedTreeItem == trtmIntroduction)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.introduction().getText());
    	}
    	else if (selectedTreeItem == trtmIntroductionModels)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.introductionModels().getText());
    	}
    	else if (selectedTreeItem == trtmIntroductionLibraries)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.introductionLibraries().getText());
    	}
    	else if (selectedTreeItem == trtmGettingStarted)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.gettingStarted().getText());
    	}
    	else if (selectedTreeItem == trtmGettingStartedReadModels)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.gettingStartedReadModels().getText());
    	}
    	else if (selectedTreeItem == trtmGettingStartedGenerateCode)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.gettingStartedGenerator().getText());
    	}
    	else if (selectedTreeItem == trtmGettingStartedVisualProcessor)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.gettingStartedVisualProcessor().getText());
    	}
    	else if (selectedTreeItem == trtmUnderTheHood)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.underTheHood().getText());
    	}
    	else if (selectedTreeItem == trtmUnderTheHoodWhyNot)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.underTheHoodWhyNot().getText());
    	}
    	else if (selectedTreeItem == trtmProjectRoadmap)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.projectRoadMap().getText());
    	}
    	else if (selectedTreeItem == trtmProjectRoadmapJPA)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.projectRoadMapJPA().getText());
    	}
    	else if (selectedTreeItem == trtmLibraries)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.libraries().getText());
    	}
    	else if (selectedTreeItem == trtmLibrariesCore)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.librariesCore().getText());
    	}
    	else if (selectedTreeItem == trtmLibrariesCoreSwingUI)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.librariesCoreSwingUI().getText());
    	}
    	else if (selectedTreeItem == trtmLibrariesGenerate)
    	{
    		html = new HTML(JMDAClientBundle.INSTANCE.librariesGenerate().getText());
    	}
    	else
    	{
    		return;
    	}
  		
  		centerVerticalPanel.clear();
  		
  		html.setStyleName("defaultHTML");
  		html.setHeight(centerHeigthPx + "px");
  		html.setWidth((centerWidthPx - 12) + "px");

  		ScrollPanel scrollPanel = new ScrollPanel();

  		scrollPanel.add(html);

  		centerVerticalPanel.add(scrollPanel);
    }
	}
	
	private TreeSelectionHandler treeSelectionHandler = new TreeSelectionHandler();
	private VerticalPanel centerVerticalPanel;

	private TreeItem trtmHome;
	private TreeItem trtmIntroduction;
	private TreeItem trtmIntroductionModels;
	private TreeItem trtmIntroductionLibraries;
	private TreeItem trtmGettingStarted;
	private TreeItem trtmGettingStartedReadModels;
	private TreeItem trtmGettingStartedGenerateCode;
	private TreeItem trtmGettingStartedVisualProcessor;
	private TreeItem trtmUnderTheHood;
	private TreeItem trtmUnderTheHoodWhyNot;
	private TreeItem trtmLibraries;
	private TreeItem trtmLibrariesCore;
	private TreeItem trtmLibrariesCoreSwingUI;
	private TreeItem trtmLibrariesGenerate;
	private TreeItem trtmOtherMDAApproaches;
	private TreeItem trtmDayToDayJMDA;

	private Anchor anchorJavadocJMDACore;
	private Anchor anchorJavadocJMDACoreUI;
	private Anchor anchorJavadocJMDAGen;
	private Anchor anchorUserDocumentation;
	private TreeItem trtmProjectRoadmap;
	private TreeItem trtmProjectRoadmapJPA;

	public void onModuleLoad()
	{
		RootLayoutPanel rootLayoutPanel = RootLayoutPanel.get();
		rootLayoutPanel.setStyleName("rootLayoutPanel");
		rootLayoutPanel.setHeight(totalHeigthPx + "px");
		rootLayoutPanel.setWidth(totalWidthPx + "px");
		
		DockLayoutPanel dockLayoutPanel = new DockLayoutPanel(Unit.EM);
		
		HorizontalPanel northHorizontalPanel = new HorizontalPanel();
		northHorizontalPanel.setStyleName("dockLayoutPanelBorder");
		northHorizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		northHorizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		northHorizontalPanel.setWidth(totalWidthPx + "px");
		dockLayoutPanel.addNorth(northHorizontalPanel, 2.0);
		
		HorizontalPanel southHorizontalPanel = new HorizontalPanel();
		southHorizontalPanel.setStyleName("dockLayoutPanelBorder");
		southHorizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		southHorizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		southHorizontalPanel.setWidth(totalWidthPx + "px");
		dockLayoutPanel.addSouth(southHorizontalPanel, 2.0);
		
		VerticalPanel westVerticalPanel = new VerticalPanel();
		westVerticalPanel.setStyleName("dockLayoutPanelBorder");
		dockLayoutPanel.addWest(westVerticalPanel, 12.3);
		
		VerticalPanel eastVerticalPanel = new VerticalPanel();
		eastVerticalPanel.setStyleName("dockLayoutPanelBorder");
		dockLayoutPanel.addEast(eastVerticalPanel, 10.0);

		centerVerticalPanel = new VerticalPanel();
		centerVerticalPanel.setHeight(centerHeigthPx + "px");
		centerVerticalPanel.setWidth(centerWidthPx + "px");
		dockLayoutPanel.add(centerVerticalPanel);

		ScrollPanel scrollPanel = new ScrollPanel();

		HTML html = new HTML(JMDAClientBundle.INSTANCE.home().getText());
		html.setStyleName("defaultHTML");
		html.setHeight(centerHeigthPx + "px");
		html.setWidth((centerWidthPx - 15) + "px");
		scrollPanel.add(html);

		centerVerticalPanel.add(scrollPanel);

		Label lblJMDAWebHome = new Label("jMDA Web Home");
		lblJMDAWebHome.setStyleName("h1");
		lblJMDAWebHome.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		northHorizontalPanel.add(lblJMDAWebHome);

		Anchor anchorProjectHosting =
				new Anchor(
						"project hosting", "http://code.google.com/p/jmda/", "_blank");
		anchorProjectHosting.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		eastVerticalPanel.add(anchorProjectHosting);
		
		anchorUserDocumentation = new Anchor();
		anchorUserDocumentation.setHTML("user documentation (.pdf)");
//		anchorUserDocumentation.setHref("static.content/jMDA.pdf");
		anchorUserDocumentation.setHref("http://code.google.com/p/jmda/downloads/detail?name=jMDA.pdf");
		anchorUserDocumentation.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		eastVerticalPanel.add(anchorUserDocumentation);
		
		anchorJavadocJMDACore = new Anchor();
		anchorJavadocJMDACore.setHref("static.content/javadoc/jmda.core/index.html");
		anchorJavadocJMDACore.setHTML("javadoc jMDA core");
		anchorJavadocJMDACore.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		eastVerticalPanel.add(anchorJavadocJMDACore);
		
		anchorJavadocJMDAGen = new Anchor();
		anchorJavadocJMDAGen.setHTML("javadoc jMDA gen");
		anchorJavadocJMDAGen.setHref("static.content/javadoc/jmda.gen/index.html");
		anchorJavadocJMDAGen.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		eastVerticalPanel.add(anchorJavadocJMDAGen);
		
		anchorJavadocJMDACoreUI = new Anchor();
		anchorJavadocJMDACoreUI.setHTML("javadoc jMDA core ui");
		anchorJavadocJMDACoreUI.setHref("static.content/javadoc/jmda.core.swingui/index.html");
		anchorJavadocJMDACoreUI.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		eastVerticalPanel.add(anchorJavadocJMDACoreUI);
		
		Tree tree = new Tree();
		tree.addSelectionHandler(treeSelectionHandler);
		westVerticalPanel.add(tree);

		trtmHome = new TreeItem("home");
		trtmHome.setText("home");
		tree.addItem(trtmHome);
		
		trtmIntroduction = new TreeItem("introduction");
		tree.addItem(trtmIntroduction);
		
		trtmIntroductionModels = new TreeItem("New item");
		trtmIntroductionModels.setText("models");
		trtmIntroduction.addItem(trtmIntroductionModels);
		
		trtmIntroductionLibraries = new TreeItem("New item");
		trtmIntroductionLibraries.setText("libraries");
		trtmIntroduction.addItem(trtmIntroductionLibraries);
		trtmIntroduction.setState(true);
		
		trtmGettingStarted = new TreeItem("getting started");
		trtmGettingStarted.setText("getting started");
		tree.addItem(trtmGettingStarted);
		
		trtmGettingStartedReadModels = new TreeItem("getting started");
		trtmGettingStarted.addItem(trtmGettingStartedReadModels);
		trtmGettingStartedReadModels.setText("read models");
		
		trtmGettingStartedGenerateCode = new TreeItem("overview");
		trtmGettingStarted.addItem(trtmGettingStartedGenerateCode);
		trtmGettingStartedGenerateCode.setText("generate code");
		
		trtmGettingStartedVisualProcessor = new TreeItem("New item");
		trtmGettingStarted.addItem(trtmGettingStartedVisualProcessor);
		trtmGettingStartedVisualProcessor.setText("process visually");
		trtmGettingStarted.setState(true);
		
		trtmUnderTheHood = new TreeItem("under the hood");
		trtmUnderTheHood.setText("under the hood");
		tree.addItem(trtmUnderTheHood);
		
		trtmUnderTheHoodWhyNot = new TreeItem("why not ...");
		trtmUnderTheHoodWhyNot.setText("why not ...");
		trtmUnderTheHood.addItem(trtmUnderTheHoodWhyNot);
		trtmUnderTheHood.setState(true);
		
		trtmProjectRoadmap = new TreeItem("project roadmap");
		trtmProjectRoadmap.setText("project roadmap");
		tree.addItem(trtmProjectRoadmap);
		
		trtmProjectRoadmapJPA = new TreeItem("jpa");
		trtmProjectRoadmapJPA.setText("jpa");
		trtmProjectRoadmap.addItem(trtmProjectRoadmapJPA);
		trtmProjectRoadmap.setState(true);
		
		trtmLibraries = new TreeItem("libraries");
		tree.addItem(trtmLibraries);
		
		trtmLibrariesCore = new TreeItem("core");
		trtmLibraries.addItem(trtmLibrariesCore);
		
		trtmLibrariesGenerate = new TreeItem("generate");
		trtmLibraries.addItem(trtmLibrariesGenerate);
		
		trtmLibrariesCoreSwingUI = new TreeItem("core swing ui");
		trtmLibraries.addItem(trtmLibrariesCoreSwingUI);
		trtmLibraries.setState(true);
		
		trtmDayToDayJMDA = new TreeItem("day-to-day jMDA");
		trtmDayToDayJMDA.setText("day-to-day jMDA");
		tree.addItem(trtmDayToDayJMDA);
		
		trtmOtherMDAApproaches = new TreeItem("New item");
		trtmOtherMDAApproaches.setText("other MDA approaches");
		tree.addItem(trtmOtherMDAApproaches);
		
		rootLayoutPanel.add(dockLayoutPanel);
	}
}